angular.module('U9ImHd.services')

.factory('AppManager', ['$q', 'Config', 'Help', 'APPCONSTANTS',
    function($q, Config, Help, APPCONSTANTS) {
        var amDefer = $q.defer(),
            _apps = [],
            o = {
                loaded: amDefer.promise
            };

        o.getApps = function () {
            var results = [];
            angular.forEach(angular.copy(_apps), function (app) {
                app.DisplayImage = Help.getFullPath(app.DisplayImage, app.AppID);
                if (app.MouseDownImage) {
                    app.MouseDownImage = Help.getFullPath(app.MouseDownImage, app.AppID);
                }
                results.push(app);
            });
            return results;
        };

        init();

        return o;

        function init () {
            Config.loaded.finally(function () {
                _apps = Config.get('apps');
                amDefer.resolve();
            });
        }
    }
]);
